/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ihc.terminalbanco.gui;

import ihc.terminalbanco.testDatas.Datas;
import ihc.terminalbanco.testDatas.FileUtilities;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author rafael
 */
public class FrameTerminal extends JFrame {

    Datas coletandoDados;

    public FrameTerminal(String title, GraphicsConfiguration gc, Datas coletandoDados) {
        super(title, gc);
        this.coletandoDados = coletandoDados;
    }

    public FrameTerminal(String title, Datas coletandoDados) throws HeadlessException {
        super(title);
        this.coletandoDados = coletandoDados;
    }

    public FrameTerminal(GraphicsConfiguration gc, Datas coletandoDados) {
        super(gc);
        this.coletandoDados = coletandoDados;
    }

    public FrameTerminal(Datas coletandoDados) throws HeadlessException {
        this.coletandoDados = coletandoDados;
    }

    

        /**
     * Since we want to control what happens when a user attempts to close
     * out the frame, we need to override the
     * javax.swing.JFrame.processWindowEvent() method.
     * @param e WindowEvent being passed as a result of user actions at the
     *          Window level.
     */
    protected void processWindowEvent(WindowEvent e) {

        if (e.getID() == WindowEvent.WINDOW_CLOSING) {

            int exit = JOptionPane.showConfirmDialog(this, "Você deseja encerrar o teste?");
            if (exit == JOptionPane.YES_OPTION) {
                try {
                    coletandoDados.setEndTime();
                    if (!coletandoDados.isModoTeste()) {
                        FileUtilities.salvar("testeInterface1.txt", coletandoDados.toString(), true);
                    }
                    System.exit(0);
                } catch (IOException ex) {
                    Logger.getLogger(FrameTerminal.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        } else {

            // If you do not want listeners processing the WINDOW_CLOSING
            // events, you could this next call in an else block for the:
            //     if (e.getID() ...)
            // statement. That way, only the other types of Window events
            // (iconification, activation, etc.) would be sent out.

            super.processWindowEvent(e);
        }
    }


}
